package com.clgk.wechatmall.role.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.clgk.wechatmall.common.sql.Page;
import com.clgk.wechatmall.common.Response;
import com.clgk.wechatmall.common.ThreadLocals;
import com.clgk.wechatmall.role.service.RoleService;
import com.clgk.wechatmall.role.bean.RoleBean;

@Controller
@RequestMapping("role")
public class RoleAction {
	@Resource RoleService roleService;
	
	
	
	/**
	 * 保存角色
	 * @param bean
	 */
	@RequestMapping("save")
	@ResponseBody
	public Response<Long> save(RoleBean bean){
		Response<Long> response = new Response<Long>();
		if(bean.getId()==null){
			bean.setManagerid(ThreadLocals.getBackUser().getId());
			response.setData(this.roleService.save(bean));
		}else{
			this.roleService.update(bean);
		}
		return response;
	}
	
	/**
	 * 修改角色
	 * @param bean
	 */
	@RequestMapping("update")
	@ResponseBody
	public Response<Integer> update(RoleBean bean){
		Response<Integer> response = new Response<Integer>(); 
		response.setData(this.roleService.update(bean));
		return response;
	}
	
	/**
	 * 查询角色
	 * @param bean
	 * @param page
	 * 
	 */
	@RequestMapping("queryList")
	@ResponseBody
	public Response<List<RoleBean>> queryList(RoleBean bean,Page page) {
		Response<List<RoleBean>> response = new Response<List<RoleBean>>(); 
		List<RoleBean> list=this.roleService.queryList(bean, page);
		response.setData(list);
		response.setPage(page);
		return response;
	}
	
	
	
	
	/**
	 * 删除角色
	 * @param ids
	 */
	@RequestMapping("deleteByIds")
	@ResponseBody
	public Response<Integer> deleteByIds(String ids) {
		Response<Integer> response = new Response<Integer>(); 
		response.setData(this.roleService.deleteByIds(ids));
		return response;
	}

}
